//
//  EmoticonManager.swift
//  表情键盘
//
//  Created by 李国伟 on 15/12/15.
//  Copyright © 2015年 李国伟. All rights reserved.
//

import Foundation

class EmoticonManager {
    
   lazy var emoticonPackage = [AnyObject]()
    
    init(){
       //首先拼接一个空的包设置为默认
       emoticonPackage.append(EmoticonPackage(dict: ["group_name_cn":"最近"]))
        
       //拼接字符串找到对应的plist文件
        let path = NSBundle.mainBundle().pathForResource("emoticons.plist", ofType: nil, inDirectory: "Emoticons.bundle")!
        
        // 2. 加载`字典`
        let dict = NSDictionary(contentsOfFile: path) as! [String: AnyObject]
        let array = (dict["packages"] as! NSArray).valueForKey("id")
        for id in array as! [String] {
         loadPackage(id)
        }
    }
    
    //添加模型
    private func loadPackage(id: String){
        
        //拼接字符串,因为是目录所以必须用这个方法
        let path = NSBundle.mainBundle().pathForResource("info.plist", ofType: nil, inDirectory: "Emoticons.bundle/\(id)")!
        let dic = NSDictionary(contentsOfFile: path) as! [String : AnyObject]
        emoticonPackage.append(EmoticonPackage(dict: dic))
    }
}